package com.ssh.action.sina.weibo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import weibo4j_2.util.WeiboConfig;


import com.ssh.action.BaseAction;

public class AccessTokenAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3146120757824337399L;

	@Override
	public String execute() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		String code = request.getParameter("code");
		String access_token = request.getParameter("access_token");
		if(code != null && code != ""){
			String clientID= WeiboConfig.getValue("client_ID");
			String client_SERCRET= WeiboConfig.getValue("client_SERCRET");
			String redirect_uri= "http://www.pengpeng.com/player.do";
			String url = "https://api.weibo.com/oauth2/access_token?client_id=" + clientID + "&client_secret=" + client_SERCRET + "&grant_type=authorization_code&redirect_uri=" + redirect_uri + "&code=" + code;
			response.sendRedirect(url);
		}
		
		if(access_token != null){
			//将access_token写入cookie备用
		}
		
		return null;
	}
}
